#ifndef _VL6180_H
#define _VL6180_H

#define VL6180_ADDRESS 0x52

#define VL6180_REG_IDENTIFICATION_MODEL_ID 0
#define VL6180_REG_IDENTIFICATION_MODEL_REV_MAJOR 0x0100
#define VL6180_REG_IDENTIFICATION_MODEL_REV_MINOR 0x0200
#define VL6180_REG_IDENTIFICATION_MODULE_REV_MAJOR 0x0300
#define VL6180_REG_IDENTIFICATION_MODULE_REV_MINOR 0x0400
#define VL6180_REG_IDENTIFICATION_DATE_HI 0x0600
#define VL6180_REG_IDENTIFICATION_DATE_LO 0x0700
#define VL6180_REG_IDENTIFICATION_TIME_HI 0x0800
#define VL6180_REG_IDENTIFICATION_TIME_LO 0x0900
#define VL6180_REG_SYSTEM_MODE_GPIO0 0x1000
#define VL6180_REG_SYSTEM_MODE_GPIO1 0x1100
#define VL6180_REG_SYSTEM_HISTORY_CTRL 0x1200
#define VL6180_REG_SYSTEM_INTERRUPT_CONFIG_GPIO 0x1400
#define VL6180_REG_SYSTEM_INTERRUPT_CLEAR 0x1500
#define VL6180_REG_SYSTEM_FRESH_OUT_OF_RESET 0x1600
#define VL6180_REG_SYSTEM_GROUPED_PARAMETER_HOLD 0x1700
#define VL6180_REG_SYSRANGE_START 0x1800
#define VL6180_REG_SYSRANGE_THRESH_HIGH 0x1900
#define VL6180_REG_SYSRANGE_THRESH_LOW 0x1A00
#define VL6180_REG_SYSRANGE_INTERMEASUREMENT_PERIOD 0x1B00
#define VL6180_REG_SYSRANGE_MAX_CONVERGENCE_TIME 0x1C00
#define VL6180_REG_SYSRANGE_CROSSTALK_COMPENSATION_RATE 0x1E00
#define VL6180_REG_SYSRANGE_CROSSTALK_VALID_HEIGHT 0x2100
#define VL6180_REG_SYSRANGE_EARLY_CONVERGENCE_ESTIMATE 0x2200
#define VL6180_REG_SYSRANGE_PART_TO_PART_RANGE_OFFSET 0x2400
#define VL6180_REG_SYSRANGE_RANGE_IGNORE_VALID_HEIGHT 0x2500
#define VL6180_REG_SYSRANGE_RANGE_IGNORE_THRESHOLD 0x2600
#define VL6180_REG_SYSRANGE_MAX_AMBIENT_LEVEL_MULT 0x2C00
#define VL6180_REG_SYSRANGE_RANGE_CHECK_ENABLES 0x2D00
#define VL6180_REG_SYSRANGE_VHV_RECALIBRATE 0x2E00
#define VL6180_REG_SYSRANGE_VHV_REPEAT_RATE 0x3100
#define VL6180_REG_SYSALS_START 0x3800
#define VL6180_REG_SYSALS_THRESH_HIGH 0x3A00
#define VL6180_REG_SYSALS_THRESH_LOW 0x3C00
#define VL6180_REG_SYSALS_INTERMEASUREMENT_PERIOD 0x3E00
#define VL6180_REG_SYSALS_ANALOGUE_GAIN 0x3F00
#define VL6180_REG_SYSALS_INTEGRATION_PERIOD 0x4000
#define VL6180_REG_RESULT_RANGE_STATUS 0x4D00
#define VL6180_REG_RESULT_ALS_STATUS 0x4E00
#define VL6180_REG_RESULT_INTERRUPT_STATUS_GPIO 0x4F00
#define VL6180_REG_RESULT_ALS_VAL 0x5000
#define VL6180_REG_RESULT_HISTORY_BUFFER_0 0x5200
#define VL6180_REG_RESULT_HISTORY_BUFFER_1 0x5400
#define VL6180_REG_RESULT_HISTORY_BUFFER_2 0x5600
#define VL6180_REG_RESULT_HISTORY_BUFFER_3 0x5800
#define VL6180_REG_RESULT_HISTORY_BUFFER_4 0x5A00
#define VL6180_REG_RESULT_HISTORY_BUFFER_5 0x5C00
#define VL6180_REG_RESULT_HISTORY_BUFFER_6 0x5E00
#define VL6180_REG_RESULT_HISTORY_BUFFER_7 0x6000
#define VL6180_REG_RESULT_RANGE_VAL 0x6200
#define VL6180_REG_RESULT_RANGE_RAW 0x6400
#define VL6180_REG_RESULT_RANGE_RETURN_RATE 0x6600
#define VL6180_REG_RESULT_RANGE_REFERENCE_RATE 0x6800
#define VL6180_REG_RESULT_RANGE_RETURN_SIGNAL_COUNT 0x6C00
#define VL6180_REG_RESULT_RANGE_REFERENCE_SIGNAL_COUNT 0x7000
#define VL6180_REG_RESULT_RANGE_RETURN_AMB_COUNT 0x7400
#define VL6180_REG_RESULT_RANGE_REFERENCE_AMB_COUNT 0x7800
#define VL6180_REG_RESULT_RANGE_RETURN_CONV_TIME 0x7C00
#define VL6180_REG_RESULT_RANGE_REFERENCE_CONV_TIME 0x8000
#define VL6180_REG_READOUT_AVERAGING_SAMPLE_PERIOD 0x0A01
#define VL6180_REG_FIRMWARE_BOOTUP 0x1901
#define VL6180_REG_FIRMWARE_RESULT_SCALER 0x2001
#define VL6180_REG_I2C_SLAVE_DEVICE_ADDRESS 0x1202
#define VL6180_REG_INTERLEAVED_MODE_ENABLE 0xA302

typedef struct
{
  unsigned char interruptConfig;
  unsigned char sysrangeThresholdHigh;
  unsigned char sysrangeThresholdLow;
  unsigned char sysrangeIntermeasurementPeriod;
} vl6180_cfg;
unsigned int vl6180ReadRegister(unsigned short registerId, unsigned char *pData, unsigned int size);
unsigned int vl6180WriteRegister(unsigned short registerId, unsigned char *pData, unsigned int size);
unsigned int vl6180_check(void);
unsigned int vl6180_init(vl6180_cfg *cfg);
unsigned int vl6180_interruptClear(unsigned char v);
unsigned int vl6180_sysRangeStart(unsigned char v);
unsigned int vl6180_reset(void);

#endif
